#!/bin/bash -e
# shellcheck disable=SC2034

RELEASE_TOOL_VERSION=1.2.3

BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "${BASE_DIR}/environment.sh"

RELEASE_NAME=kylin-patch-installer-builder
RELEASE_VERSION=$(cat "${BASE_DIR}/VERSION")

ReleaseFile=${RELEASE_NAME}_v${RELEASE_VERSION}_all.tar.gz

declare -a ReleaseFileList

ReleaseFileList=(
    "$(realpath --relative-to="${BASE_DIR}" "${FILE_LICENSE}")"
    "$(realpath --relative-to="${BASE_DIR}" "${FILE_README}")"
    "$(realpath --relative-to="${BASE_DIR}" "${FILE_VERSION}")"
    "$(realpath --relative-to="${BASE_DIR}" "${SCRIPT_ENVIRONMENT}")"
    "$(realpath --relative-to="${BASE_DIR}" "${SCRIPT_BUILDER}")"
    "$(realpath --relative-to="${BASE_DIR}" "${BASE_DIR_EXAMPLES}")"
    "$(realpath --relative-to="${BASE_DIR}" "${BASE_DIR_SCRIPT}")"
)

while [ $# -gt 0 ]; do
    ReleaseFileList+=("$1")
    shift
done

tar -zvcf "${ReleaseFile}" "${ReleaseFileList[@]}"
